//
//  LZFightGroupDetailViewController.m
//  LzzizDemo
//
//  Created by xbnzd on 16/11/8.
//  Copyright © 2016年 xbnzd. All rights reserved.
//

#import "LZFightGroupDetailViewController.h"
#import "LZFightGroupDetailOrderRulesCell.h"
#import "LZFightGroupDetailRulesOfUseCell.h"
#import "LZFightGroupDetailMealsTimeCell.h"
#import "LZFightGroupDetailTitleCell.h"
#import "LZVideoPublisherCell.h"
#import "LZGroupListViewController.h"
#import "LZStartGroupViewController.h"
#import "UITableView+FDTemplateLayoutCell.h"
#import "LZCustomPlayerView.h"
#import "Masonry.h"
#import "UIView+Rotation.h"
#import "UIViewController+NavigationItemSetting.h"
#import "UINavigationController+FDFullscreenPopGesture.h"
#import "LZGrabCouponAndFightGroupsDetialModel.h"
#import "LZGrouponPresenter.h"
#import "XBNTimeLimitCountDownCalculator.h"
#import "LZTimeLimitCountDownJudgeDataManager.h"
#import "LZUserModel.h"
#import "LZPlayVideoManager.h"
#import "LZCheckCouponAndGrouponPresenter.h"
#import "LZPromotionStatusModel.h"
#import "LZAlertView.h"
#import "LZDateFormatterManager.h"
#import "LZCheckoutView.h"
#import "LAWriteReviewViewController.h"
#import "LZLoginViewController.h"
#import "AppDelegate.h"
#import "UIImageView+WebCache.h"

static NSString *kTitleCell = @"titleCell";
static NSString *kOrderRulesCell = @"orderRulesCell";
static NSString *kRulesOfUseCell = @"rulesOfUseCell";
static NSString *kMealsTimeCell  = @"mealsTimeCell";
static NSString *kPublisherCell  = @"publisherCell";

@interface LZFightGroupDetailViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) LZCustomPlayerView *playerView;
@property (nonatomic, strong) UIView *videoBgView;
@property (nonatomic, strong) UIImageView *videoCoverImage;
@property (strong, nonatomic) UIButton *nav_left_back;
@property (assign, nonatomic) CGFloat navbar_change_y;
@property (assign, nonatomic) CGFloat lzAlpha;
@property (nonatomic, strong) LZGrabCouponAndFightGroupsDetialModel *detailModel;
@property (weak, nonatomic) IBOutlet UIButton *joinGroupBtn;
@property (weak, nonatomic) IBOutlet UIButton *startGroupBtn;
@property (weak, nonatomic) IBOutlet UIButton *useCouponBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tableViewBottomConstraint;

@property (nonatomic, weak) LZCheckoutView *couponView;

@end

@implementation LZFightGroupDetailViewController
- (id)init
{
    self = [super init];
    if (self) {
        self.hidesBottomBarWhenPushed = YES;
    }
    
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.umLogPageViewName = @"拼团详情页面";
    
    [self.joinGroupBtn setTitle:LZLocalizedString(@"group_join", nil) forState:UIControlStateNormal];
    [self.startGroupBtn setTitle:LZLocalizedString(@"group_start_group", nil) forState:UIControlStateNormal];
    [self initUI];
    [self configNavigationBar];
    [self registerCell];
    
    if (self.type == GroupType_Normal) {
        [self getData];
    }
    else if (self.type == GroupType_MessageCenter) {
        [self getMessageCenterTypeData];
    }
    [self startTimeDownAction];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    [self releasePlayViewRAM];
}

- (void)dealloc
{
    DLog(@"dealloc");
}

- (BOOL)fd_prefersNavigationBarHidden {
    return YES;
}

#pragma mark -
#pragma mark network method
- (void)getData
{
    [self startLoadingViewForView:self.view loadingViewUserInteractionEnabled:NO];
    WS(wSelf);
    [LZGrouponPresenter getGrabCouponOrFightGroupsDetailWithVideoID:_videoID ResultSuccess:^(LZGrabCouponAndFightGroupsDetialModel *model) {
        
        wSelf.detailModel = model;
        
        [wSelf.videoCoverImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",APIBaseImageUrl,model.videoPhoto]] placeholderImage:[UIImage imageNamed:@"videoCoverImg"]];
        
        [wSelf.tableView reloadData];
        
        [wSelf playVideo];
        
        [wSelf stopLoadingViewForView:wSelf.view];
    } ResultFailed:^(NSString *remind) {
        [wSelf stopLoadingViewForView:wSelf.view];
    }];
}

- (void)getMessageCenterTypeData {
    
    [self startLoadingViewForView:self.view loadingViewUserInteractionEnabled:NO];
    WS(wSelf);
    
    [LZGrouponPresenter getMessageCenterTypeGrabCouponOrFightGroupsDetailWithVideoID:_videoID andType:@"2" ResultSuccess:^(LZGrabCouponAndFightGroupsDetialModel *model) {
        
        wSelf.detailModel = model;
        
        [wSelf.videoCoverImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",APIBaseImageUrl,model.videoPhoto]] placeholderImage:[UIImage imageNamed:@"videoCoverImg"]];
        
        [wSelf.tableView reloadData];
        
        [wSelf playVideo];
        
        if (model.isExpired || model.isUsed) {
            wSelf.useCouponBtn.hidden = YES;
            wSelf.joinGroupBtn.hidden = YES;
            wSelf.startGroupBtn.hidden = YES;
            wSelf.tableViewBottomConstraint.constant = 0;
        }
        
        [wSelf stopLoadingViewForView:wSelf.view];
    } ResultFailed:^(NSString *remind) {
        [wSelf stopLoadingViewForView:wSelf.view];
    }];
}

#pragma mark -
#pragma mark action
/**
 设置倒计时
 */
-(void)startTimeDownAction
{
    LZFightGroupDetailTitleCell *cell = [_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
    [_limitCountDownCalculator addProcessBlock:^(NSTimeInterval remain) {
        if (remain<=0) {
            [LZTimeLimitCountDownJudgeDataManager configLimitedLabel:cell.groupTimeDownLabel withReamin:0 andDayUnit:@"d " HourUnit:@"h " andMinuteUnit:@"m " andSecUnit:[NSString stringWithFormat:@"s %@",LZLocalizedString(@"group_left", nil)] andIsChangeUintColor:NO andDayUnitColor:nil HourUnitColor:nil andMinUnitColor:nil andSecUnitColor:nil];
//            [LZTimeLimitCountDownJudgeDataManager configLimitedLabel:cell.groupTimeDownLabel withReamin:0 andHourUnit:@"h " andMinuteUnit:@"m " andSecUnit:[NSString stringWithFormat:@"s %@",LZLocalizedString(@"group_left", nil)] andIsChangeUintColor:NO andHourUnitColor:nil andMinUnitColor:nil andSecUnitColor:nil];
        }
        else {
             [LZTimeLimitCountDownJudgeDataManager configLimitedLabel:cell.groupTimeDownLabel withReamin:remain andDayUnit:@"d " HourUnit:@"h " andMinuteUnit:@"m " andSecUnit:[NSString stringWithFormat:@"s %@",LZLocalizedString(@"group_left", nil)] andIsChangeUintColor:NO andDayUnitColor:nil HourUnitColor:nil andMinUnitColor:nil andSecUnitColor:nil];
//            [LZTimeLimitCountDownJudgeDataManager configLimitedLabel:cell.groupTimeDownLabel withReamin:remain andHourUnit:@"h " andMinuteUnit:@"m " andSecUnit:[NSString stringWithFormat:@"s %@",LZLocalizedString(@"group_left", nil)] andIsChangeUintColor:NO andHourUnitColor:nil andMinUnitColor:nil andSecUnitColor:nil];
        }
        
    } cancelBlock:^{
        
    }];
}


/**
 使用团购&优惠券

 @param sender <#sender description#>
 */
- (IBAction)useCouponBtnAction:(id)sender {
    if ([AppDelegate getDeviceToken]) {
        // 如果已经开了推送,则校验是否刚刚使用过优惠券
        WS(weakSelf)
        [LZCheckCouponAndGrouponPresenter checkUsedCouponAndGrouponResultSuccess:^(id result) {
            if (![result boolValue]) {
                // 如果没使用过,则进入付款
                [weakSelf.couponView showViewWithState:PayCouponViewState_ShowQRCode];
                
                // 禁用返回手势
                weakSelf.navigationController.fd_fullscreenPopGestureRecognizer.enabled = NO;
            }
            else {
                LZAlertView *alert = [[LZAlertView alloc] initWithContent:LZLocalizedString(@"restaurant_pay_short_time_remind", nil) andImage:nil cancelButtonTitle:nil otherButtonTitles:LZLocalizedString(@"confirm", nil),nil];
                [alert show];
            }
        } ResultFailed:^(NSString *remind) {
            
        }];
        
    }
    else {
        // 如果没开推送，则提醒用户去开推送
        LZAlertView *alert = [[LZAlertView alloc] initWithContent:LZLocalizedString(@"iphone_permissions_notification_remind", nil) andImage:nil cancelButtonTitle:LZLocalizedString(@"cancel", nil) otherButtonTitles:LZLocalizedString(@"iphone_permissions_go_setting", nil),nil];
        [alert show];
        
        alert.clickButtonIndexBlock = ^(NSInteger index) {
            if (index == 1) {
                [[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
            }
        };
    }
}


/**
 参加现在的拼团

 */
- (IBAction)joinGroupBtnAction:(id)sender {
    [self setButtonsUserInteractionEnabled:NO];
    WS(weakSelf)
    [LZCheckCouponAndGrouponPresenter checkGrouponWithPromotionId:self.detailModel.videoId ResultSuccess:^(id result) {
        [weakSelf setButtonsUserInteractionEnabled:YES];
        LZPromotionStatusModel *modelTemp = (LZPromotionStatusModel*)result;
        
        if (modelTemp.isPromotion) {
            DLog(@"已参团");
            [weakSelf showAlertView:LZLocalizedString(@"group_joined_remind", nil) andIsPopVC:NO];
        }
        else if (modelTemp.isExpired) {
            DLog(@"已过期");
            [weakSelf showAlertView:LZLocalizedString(@"group_closed_remind", nil) andIsPopVC:YES];
        }
        else if (modelTemp.isOffLine) {
            DLog(@"商家已下线");
            [weakSelf showAlertView:LZLocalizedString(@"restaurant_offline_remind", nil) andIsPopVC:YES];
        }
        else {
            LZGroupListViewController *vc = [[LZGroupListViewController alloc] init];
            vc.videoId = [weakSelf.videoID copy];
            [weakSelf.navigationController pushViewController:vc animated:YES];
        }
    } ResultFailed:^(NSString *remind) {
        [weakSelf setButtonsUserInteractionEnabled:YES];
    }];
    
}


/**
 开启一个新的拼团

 */
- (IBAction)startNewGroupBtnAction:(id)sender {
    [self setButtonsUserInteractionEnabled:NO];
    WS(weakSelf)
    [LZCheckCouponAndGrouponPresenter checkGrouponWithPromotionId:self.detailModel.videoId ResultSuccess:^(id result) {
        
        [weakSelf setButtonsUserInteractionEnabled:YES];
        
        LZPromotionStatusModel *modelTemp = (LZPromotionStatusModel*)result;
        
        if (modelTemp.isPromotion) {
            DLog(@"已参团");
            [weakSelf showAlertView:LZLocalizedString(@"group_joined_remind", nil) andIsPopVC:NO];
        }
        else if (modelTemp.isExpired) {
            DLog(@"已过期");
            [weakSelf showAlertView:LZLocalizedString(@"group_closed_remind", nil) andIsPopVC:YES];
        }
        else if (modelTemp.isOffLine) {
            DLog(@"商家已下线");
            [weakSelf showAlertView:LZLocalizedString(@"restaurant_offline_remind", nil) andIsPopVC:YES];
        }
        else {
            LZStartGroupViewController *vc = [[LZStartGroupViewController alloc] init];
            vc.rulesModel = weakSelf.detailModel;
            [weakSelf.navigationController pushViewController:vc animated:YES];
        }
    } ResultFailed:^(NSString *remind) {
        [weakSelf setButtonsUserInteractionEnabled:YES];
    }];
}

- (void)showAlertView:(NSString*)message andIsPopVC:(BOOL)isPop{
    LZAlertView *alert = [[LZAlertView alloc] initWithContent:message andImage:nil cancelButtonTitle:nil otherButtonTitles:LZLocalizedString(@"confirm", nil),nil];
    [alert show];
    
    if (isPop) {
        WS(weakSelf)
        alert.clickButtonIndexBlock = ^(NSInteger index) {
            [weakSelf.navigationController popViewControllerAnimated:YES];
        };
    }
}

-(void)navbarBackButtonClickAction:(UIButton*)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark -
#pragma mark UI
- (void)initUI
{
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.navbar_change_y = SCREEN_WIDTH/375.0*(500-40)/2.0-64;
    if (_couponState == kCoupon_used || _couponState == kCoupon_expired) {
        _useCouponBtn.hidden = YES;
        _joinGroupBtn.hidden = YES;
        _startGroupBtn.hidden = YES;
        _tableViewBottomConstraint.constant = 0;
        
    }else if (_couponState == kCoupon_notUsed){
        _useCouponBtn.hidden = NO;
        _joinGroupBtn.hidden = YES;
        _startGroupBtn.hidden = YES;
        _tableViewBottomConstraint.constant = 46;
    }
}

- (void)registerCell
{
    [self.tableView registerNib:[UINib nibWithNibName:@"LZFightGroupDetailTitleCell" bundle:nil] forCellReuseIdentifier:kTitleCell];
    [self.tableView registerNib:[UINib nibWithNibName:@"LZFightGroupDetailOrderRulesCell" bundle:nil] forCellReuseIdentifier:kOrderRulesCell];
    [self.tableView registerNib:[UINib nibWithNibName:@"LZFightGroupDetailRulesOfUseCell" bundle:nil] forCellReuseIdentifier:kRulesOfUseCell];
    [self.tableView registerNib:[UINib nibWithNibName:@"LZFightGroupDetailMealsTimeCell" bundle:nil] forCellReuseIdentifier:kMealsTimeCell];
    [self.tableView registerNib:[UINib nibWithNibName:@"LZVideoPublisherCell" bundle:nil] forCellReuseIdentifier:kPublisherCell];
    
    [self.videoBgView addSubview:self.videoCoverImage];
    self.tableView.tableHeaderView = self.videoBgView;
}


#pragma mark -
#pragma mark private method
-(void)configNavigationBar{
    
    self.nav_left_back = [UIButton buttonWithType:UIButtonTypeCustom];
    self.nav_left_back.frame = CGRectMake(0, 0, 60, 40);
    [self.nav_left_back addTarget:self action:@selector(navbarBackButtonClickAction:) forControlEvents:UIControlEventTouchUpInside];
    UIImage *image_back = [UIImage imageNamed:@"navigationbar_back_circle"];
    [self.nav_left_back setImage:image_back forState:UIControlStateNormal];
    self.nav_left_back.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, CGRectGetWidth(self.nav_left_back.bounds)-image_back.size.width);
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0) {
        [self.nav_left_back setLanguageRotaion];
    }
    
    
    [self hiddenBarNavigationItemSetting:@[self.nav_left_back] type:NAVIGATIONITEMSETTING_LEFT];
    
    [self lz_setCustomBarAlpha:self.lzAlpha];
}

- (void)setButtonsUserInteractionEnabled:(BOOL)userInteractionEnabled {
    self.joinGroupBtn.userInteractionEnabled = userInteractionEnabled;
    self.startGroupBtn.userInteractionEnabled = userInteractionEnabled;
}

- (void)playVideo
{
    [[LZPlayVideoManager shareManager] playVideoWithBgView:self.videoBgView playerView:self.playerView videoURL:self.detailModel.videoUrl videoID:self.detailModel.videoId playCountAddBlock:^(NSInteger totleCount) {
        
    }];
}

/**
 离开页面,释放播放器内存
 */
- (void)releasePlayViewRAM
{
  [[LZPlayVideoManager shareManager] stopPlayWithPlayerView:self.playerView];
}

#pragma mark -
#pragma mark tableview  delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WS(wSelf);
    switch (indexPath.row) {
        case 0:
            return [tableView fd_heightForCellWithIdentifier:kTitleCell configuration:^(id cell) {
                LZFightGroupDetailTitleCell *cellTemp = (LZFightGroupDetailTitleCell *)cell;
                [cellTemp loadTitle:wSelf.detailModel.grouponName CouponState:_couponState];
            }];
            break;
        case 1:
            return [tableView fd_heightForCellWithIdentifier:kOrderRulesCell configuration:^(id cell) {
                LZFightGroupDetailOrderRulesCell *cellTemp = (LZFightGroupDetailOrderRulesCell *)cell;
                [cellTemp loadMembersNum:wSelf.detailModel.grouponCount FinishedTime:[[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:wSelf.detailModel.grouponEndTime]];
                
            }];
            break;
        case 2:
            return [tableView fd_heightForCellWithIdentifier:kRulesOfUseCell configuration:^(id cell) {
                LZFightGroupDetailRulesOfUseCell *cellTemp = (LZFightGroupDetailRulesOfUseCell *)cell;
                [cellTemp loatGrouponName:@"" RulesContent:wSelf.detailModel.grouponRemindRule ExpirationTime:[[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:wSelf.detailModel.grouponDeadline]];
            }];
            break;
        case 3:
            return [tableView fd_heightForCellWithIdentifier:kMealsTimeCell configuration:^(id cell) {
                LZFightGroupDetailMealsTimeCell *cellTemp = (LZFightGroupDetailMealsTimeCell *)cell;
                NSString *everyDayValid = [wSelf.detailModel getGroupEverydayValid];
                [cellTemp loadValidExcept:wSelf.detailModel.grouponExceptTime EverydayValid:everyDayValid otherContent:wSelf.detailModel.grouponRemindAppoint];
            }];
            break;
        case 4:
            return [tableView fd_heightForCellWithIdentifier:kPublisherCell configuration:^(id cell) {
                LZVideoPublisherCell *cellTemp = (LZVideoPublisherCell *)cell;
                [cellTemp loadPublisherName:wSelf.detailModel.restaurantName];
            }];
            break;
            
        default:
            break;
    }
    
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 0:{
            LZFightGroupDetailTitleCell *cell = [tableView dequeueReusableCellWithIdentifier:kTitleCell];
            [cell loadTitle:self.detailModel.grouponName CouponState:_couponState];
            return cell;
        }
            
            break;
        case 1:{
            LZFightGroupDetailOrderRulesCell *cell = [tableView dequeueReusableCellWithIdentifier:kOrderRulesCell];
             [cell loadMembersNum:self.detailModel.grouponCount FinishedTime:[[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:self.detailModel.grouponEndTime]];
            return cell;
        }
            
            break;
        case 2:{
            LZFightGroupDetailRulesOfUseCell *cell = [tableView dequeueReusableCellWithIdentifier:kRulesOfUseCell];
            [cell loatGrouponName:@"" RulesContent:self.detailModel.grouponRemindRule ExpirationTime:[[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:self.detailModel.grouponDeadline]];
             
            return cell;
        }
            
            break;
        case 3:{
            LZFightGroupDetailMealsTimeCell *cell = [tableView dequeueReusableCellWithIdentifier:kMealsTimeCell];
            NSString *everyDayValid = [self.detailModel getGroupEverydayValid];
            [cell loadValidExcept:self.detailModel.grouponExceptTime EverydayValid:everyDayValid otherContent:self.detailModel.grouponRemindAppoint];
            return cell;
        }
            
            break;
        case 4:{
            LZVideoPublisherCell *cell = [tableView dequeueReusableCellWithIdentifier:kPublisherCell];
            [cell loadPublisherName:self.detailModel.restaurantName];
            return cell;
        }
            
            break;
            
        default:
            break;
    }
    
    return nil;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat offsetY = scrollView.contentOffset.y;
    
    if (offsetY <= self.navbar_change_y) {
        CGFloat alpha = MIN(1, offsetY/self.navbar_change_y);
        
        self.lzAlpha = alpha;
        
        CGFloat navbar_item_alpha = fabs((alpha-0.5)/(0.5));
        self.nav_left_back.alpha = navbar_item_alpha;
        if (alpha <= 0.5) {
            [self.nav_left_back setImage:[UIImage imageNamed:@"navigationbar_back_circle"] forState:UIControlStateNormal];
        }
        else {
            [self.nav_left_back setImage:[UIImage imageNamed:@"navigationbar_back"] forState:UIControlStateNormal];
        }
        
    } else {
        self.lzAlpha = 1;
    }
    [self lz_setCustomBarAlpha:self.lzAlpha];
}

#pragma mark -
#pragma mark 空间初始化
- (UIView *)videoBgView
{
    if (!_videoBgView) {
        _videoBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH)];
        _videoBgView.backgroundColor = [UIColor blackColor];
    }
    
    return _videoBgView;
}

- (UIImageView *)videoCoverImage
{
    if (!_videoCoverImage) {
        _videoCoverImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH)];
        _videoCoverImage.backgroundColor = [UIColor blackColor];
        
        _videoCoverImage.userInteractionEnabled = YES;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(playVideo)];
        [_videoCoverImage addGestureRecognizer:tap];

    }
    
    return _videoCoverImage;
}

- (LZCustomPlayerView *)playerView
{
    if (!_playerView) {
        _playerView = [[LZCustomPlayerView alloc] init];
        _playerView.playCircle = NO;
    }
    
    return _playerView;
}

- (LZCheckoutView*)couponView {
    if (_couponView) {
        return _couponView;
    }
    
    LZCheckoutView *v = [[LZCheckoutView alloc] initWithFrame:self.navigationController.view.bounds];
    v.isUseCouponOpen = YES;
    if (self.type == GroupType_Normal) {
        v.disCountNo = [self.disCountNo copy];
    }
    else if (self.type == GroupType_MessageCenter) {
        v.disCountNo = [self.videoID copy];
    }
    v.promotionType = [@"2" copy];
    [self.navigationController.view addSubview:v];
    
    WS(weakSelf)
    
    v.stateBlock = ^(PayCouponViewState state) {
        if (state == PayCouponViewState_Remove) {
            // 开启返回手势
            weakSelf.navigationController.fd_fullscreenPopGestureRecognizer.enabled = YES;
        }
    };
    
    v.reviewBlock = ^(NSString *sellerId,NSString *promotionId,NSString *noRemarkId) {
        // 点击评价按钮 进入评价页面
        
        if ([[LZUserModel Instance] isLogin]) {
            LAWriteReviewViewController *vc = [[LAWriteReviewViewController alloc] initWithNibName:@"LAWriteReviewViewController" bundle:nil] ;
            vc.type = WriteReviewType_Video;
            vc.sellerId = [sellerId copy];
            vc.videoId = [promotionId copy];
            vc.video_noRemarkId = [noRemarkId copy];
            
            [weakSelf.navigationController pushViewController:vc animated:YES];
        }
        else {
            // 如果未登录
            LZLoginViewController * vc = [[LZLoginViewController alloc] init];
            [weakSelf.navigationController pushViewController:vc animated:YES];
        }
        
    };
    
    _couponView = v;
    return _couponView;
}

#pragma mark -
#pragma mark public method
- (BOOL)checkAndDealNotificaton:(NSDictionary*)notificationDic {
    
    _couponState = kCoupon_used;
    _useCouponBtn.hidden = YES;
    _joinGroupBtn.hidden = YES;
    _startGroupBtn.hidden = YES;
    _tableViewBottomConstraint.constant = 0;
    [self.tableView reloadData];
    
    if (_couponView) {
        
        NSDictionary *extra = notificationDic[@"extras"];
        [self.couponView scanQRCodeSuccessWithSellerId:extra[@"sellerId"] andPromotionId:extra[@"promotionId"] andNoRemarkId:extra[@"noRemarkId"]];
        
        return YES;
    }
    else {
        return NO;
    }
}

@end
